package com.soilflow.common.exception;

import com.soilflow.common.utils.StringUtils;

/**
 * @author dhp
 * @date 2022/6/30 - 9:52
 */
public class AsserUtil {
    public  static  void  assertNullAndThrow(Object str, String errorMsg){
        if (str instanceof  String && StringUtils.isEmpty((String) str)){
            throw  new ServiceException(errorMsg);
        }
        if (str==null){
            throw  new ServiceException(errorMsg);
        }
    }
    public  static  void  assertNullAndThrow(Object str, String errorMsg,int i){
        if (str instanceof  String && StringUtils.isEmpty((String) str)){
            throw  new ServiceException("第"+i+"行数据"+errorMsg);
        }
        if (str==null){
            throw  new ServiceException("第"+i+"行数据"+errorMsg);
        }
    }
    public  static  void  assertFalseAndThrow(Boolean condition, String errorMsg,int i){
        if (!condition){
            throw  new ServiceException(errorMsg);
        }
    }
}
